#include "../sort.hpp"
#include <eclock.hpp>


/*!
 * 插入排序
 */
double SortInsertion(int *data, size_t size)
{
	double res = 0;
	int tmp;
	int j;

	EClock<> Ek;
	for(size_t i=1; i<size; i++) {
		tmp = data[i];
		j = i-1;
		while(j>=0 && data[j] > tmp) {
			data[j+1] = data[j];
			j--;
		}
		data[j+1] = tmp;
	}
	res = Ek.microsecond();
	return res;
}

/*!
 * 选择排序
 */
double SortSelection(int *data, size_t size)
{
	double res = 0;
	int tmp;
	size_t K;

	EClock<> Ek;
	for(size_t i=0; i<size-1; i++) {
		K = i;
		for(size_t j=i+1; j<size; j++) {
			if(data[K] > data[j]) {
				K = j;
			}
		}
		if(K > i) {
			tmp = data[K];
			data[K] = data[i];
			data[i] = tmp;
		}
	}
	res = Ek.microsecond();
	return res;
}


/*!
 * 冒泡排序
 */
double SortBubble(int *data, size_t size)
{
	double res = 0;
	int tmp;

	EClock<> Ek;
	for(size_t i=0; i<size-1; i++) {
		for(size_t j=0; j<size-i-1; j++) {
			if(data[j] > data[j+1]) {
				tmp = data[j];
				data[j] = data[j+1];
				data[j+1] = tmp;
			}
		}
	}
	res = Ek.microsecond();

	return res;
}

/*!
 * 快速排序
 */
double SortQuick(int *data, size_t size)
{
	double res = 0;
	
	return res;
}
